package cn.tedu._07springaop.egaop1;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 切面类
 */
@Aspect
@Component
public class OrderCheckAspect {
    @Before(value = "execution(public void cn.tedu._07springaop.egaop1.OrderServiceImpl.*(..))")
    public void check(JoinPoint joinPoint) {
        // 获取参数:订单数量
        Integer number = (Integer) joinPoint.getArgs()[0];
        if (number < 0) {
            throw new IllegalArgumentException("订单数量不能小于0");
        }
        System.out.println("number = " + number);
        ;
    }
}
